
function mysubmit() {
    var username = jQuery("#username");
    var password1 = jQuery("#password1");
    var password2 = jQuery("#password2");

    // 验证用户名和密码只包含字母和数字
    var alphanumericPattern = /^[a-zA-Z0-9]+$/;

    if (username.val().trim() === "") {
        alert("请先输入用户名！");
        username.focus();
        return false;
    }
    if (!alphanumericPattern.test(username.val().trim())) {
        alert("用户名只允许使用字母和数字！");
        username.focus();
        return false;
    }
    if (username.val().trim().length < 4) {
        alert("用户名少于4位！");
        username.focus();
        return false;
    }

    if (password1.val().trim() === "") {
        alert("请先输入密码！");
        password1.focus();
        return false;
    }
    if (!alphanumericPattern.test(password1.val().trim())) {
        alert("密码只允许使用字母和数字！");
        password1.focus();
        return false;
    }
    if (password1.val().trim().length < 6) {
        alert("密码少于6位！");
        password1.focus();
        return false;
    }

    if (password2.val().trim() === "") {
        alert("请先输入确认密码！");
        password2.focus();
        return false;
    }

    if (password1.val() !== password2.val()) {
        alert("两次输入密码不一致，请先检查！");
        password1.focus();
        return false;
    }

    jQuery("#submit").attr("disabled", "disabled");

    jQuery.ajax({
        url: "/user/reg",
        type: "POST",
        data: {
            "username": username.val().trim(),
            "password": password1.val().trim()
        },
        success: function (res) {
            if (res.code === 200 && res.data === 1) {
                alert("注册成功！");
                location.href = "login.html";
            } else {
                alert("注册失败！" + "该用户已存在！");
                jQuery("#submit").removeAttr("disabled");
            }
        }
    });
}
